package typeConversion

import (
	"errors"
	"fmt"
	"strconv"
)

func ToFloat32(p_in interface{}) (float32, error) {
	if p_in == nil {
		return 0, errors.New("too.typeConversion ToInt err: Parameters not supported, Parameters is nil")
	}

	switch p_in.(type) {
	case string:
		if f, err := strconv.ParseFloat(p_in.(string), 32); err != nil {
			return 0, err
		} else {
			return float32(f), nil
		}
	case float64:
		return float32(p_in.(float64)), nil
	case float32:
		return p_in.(float32), nil
	case int:
		return float32(p_in.(int)), nil
	case int32:
		return float32(p_in.(int32)), nil
	case int64:
		return float32(p_in.(int64)), nil
	default:
		return 0, errors.New("too.typeConversion ToFloat32 err: Parameters not supported,The parameter type is " + fmt.Sprintf("%T", p_in))
	}
}
